package nixonftp.list;

/* nixonFTP
 * FTP client version 0.1
 * Copyright (C) 2010 NIXON Development Corporation.
 * All rights reserved.
 * http://members.shaw.ca/nixon.com
*/



import nixonftp.*;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import java.awt.Component;
import javax.swing.BorderFactory;

public class NXTableRenderer extends JLabel implements TableCellRenderer {
	private final boolean isBordered;

    public NXTableRenderer(boolean isBordered) {
        this.isBordered = isBordered;
        setOpaque(true); //MUST do this for background to show up.
    }

    public Component getTableCellRendererComponent(
                            JTable table, Object obj,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
        
        if (isBordered) {
            if (isSelected) {
                //selectedBorder is a solid border in the color
                //table.getSelectionBackground().
					 setBackground(table.getSelectionBackground());
					 setForeground(table.getSelectionForeground());
            } else {
                //unselectedBorder is a solid border in the color
                //table.getBackground().
                setBackground(table.getBackground());
					 setForeground(table.getForeground());
            }
        }

		  NXObjectIndex idx = (NXObjectIndex) obj;

		  setIcon(null);
		  setIconTextGap(8);
		  setBorder(BorderFactory.createEmptyBorder(6,6,6,6));
		  this.setToolTipText(null);

		  switch (column) {
			  case 0:
				  setIcon(NXIcon.small[idx.type]);
				  setText(idx.name);
				  break;
			  case 1:
				  setText(NXFormat.fileSize(idx.size, true));
				  if (idx.size > 1023) setToolTipText(idx.size + " bytes");
				  break;
			  case 2:
				  setText(idx.date.toString());
				  setToolTipText(NXFormat.parseDate(idx.date));
				  break;
		  }
		  
        return this;
    }
}
